package com.neuedu.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.service.Userservice;
import com.neusoft.entity.User;
/**
 * Servlet implementation class login
 */
@WebServlet("/loginServ")
public class loginServ extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public loginServ() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String username = request.getParameter("userName");
		String psw = request.getParameter("passWord");
		System.out.println("用户名"+username+","+psw);
		Userservice userservice = new Userservice ();
		User user = new User (username,psw);
		boolean judgeUserIsExist = userservice.judgeUserIsExist(user);
		if(judgeUserIsExist==true)
		{
			request.setAttribute("name",username);
			request.getRequestDispatcher("success.jsp").forward(request, response);
			return;
		}
		response.sendRedirect("LOGIN.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
